package com.cdty.chess.util;

import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import java.util.Base64;

/**
 * 密码加密
 */
public class AESUtils {

    private static final String KEY = "1234567890123456"; // 密钥，需要与前端保持一致

    public static String decrypt(String encryptedParam) {
        try {
            byte[] encryptedBytes = Base64.getDecoder().decode(encryptedParam);
            SecretKeySpec secretKeySpec = new SecretKeySpec(KEY.getBytes(), "AES");
            Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
            cipher.init(Cipher.DECRYPT_MODE, secretKeySpec);
            byte[] decryptedBytes = cipher.doFinal(encryptedBytes);
            return new String(decryptedBytes);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

}
